Dynomotion

Group: DynoMotion Message: 603 From: ekonradsson Date: 8/24/2010
Subject: Need help with a frequency generator.
I posted a few weeks ago about how to use the PWM generator to generate a 25Khz signal. I managed through trial and error to approximate the signal using the step and direction channels but never figured out exactly how it works.
It turns out I need a 12.5 Khz signal at 50% duty cycle, not the 25 Khz but cant figure out how to calculate it properly. Can anyone help?

The code below is based on an example program that came with the controller.

void StartChargePump()
{
int Frequency;
double DutyCycle, Period;

int Pulse=200; // 1000 Gives approx, 5Khz signal. 200 gives approx 25 khz signal

FPGA(STEP_PULSE_LENGTH_ADD) = Pulse;

DutyCycle= 0.2978; // Note Duty Cycle can't be zero (useful range 0.02 - 0.98)

Period = Pulse/DutyCycle;

Frequency = (int)(0x7FFFFF/Period);

FPGA(STEP_RATE_ADD+0) = Frequency; // put 23 bit frequency
FPGA(STEP_RATE_ADD+1) = Frequency>>8;
FPGA(STEP_RATE_ADD+2) = Frequency>>16;
FPGA(STEP_RATE_ADD+3) = 0x88 + SCHPChanel; // combine enable, Drive High and low mode, channel
}

Thanks
EK
Group: DynoMotion Message: 605 From: Tom Kerekes Date: 8/25/2010
Subject: Re: Need help with a frequency generator.
Hi EK,
 
You can't get a 50% duty cycle pulse at 25KHz with the Step/Dir Generators because that would require a 20us pulse every 40us.  The max pulse size for the Step/Dir Generator is ~4us (setting of 63 at 16.67MHz).
 
Your code example below is setting a value larger than 63 as the pulse length.
Consider using a PWM to generate the signal.  You won't be able to generate exactly 25 KHz but I can't imagine that the frequency would be critical for a charge pump.
 
Regards
TK

Group: DynoMotion Message: 608 From: ekonradsson Date: 8/25/2010
Subject: Re: Need help with a frequency generator.
That might explain my problem. But if a stay with the Step/Dir generator and use 4us pulse, how would I set it up for approx 12.5 khz frequency?


Thanks
EK

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi EK,
>
> You can't get a 50% duty cycle pulse at 25KHz with the Step/Dir Generators
> because that would require a 20us pulse every 40us.  The max pulse size for the
> Step/Dir Generator is ~4us (setting of 63 at 16.67MHz).
>
> Your code example below is setting a value larger than 63 as the pulse length.
>
> Consider using a PWM to generate the signal.  You won't be able to generate
> exactly 25 KHz but I can't imagine that the frequency would be critical for a
> charge pump.
>
> Regards
> TK
>
>
>
> ________________________________
> From: ekonradsson <erlendur.konradsson@...>
> To: DynoMotion@yahoogroups.com
> Sent: Tue, August 24, 2010 5:04:52 PM
> Subject: [DynoMotion] Need help with a frequency generator.
>
>  
> I posted a few weeks ago about how to use the PWM generator to generate a 25Khz
> signal. I managed through trial and error to approximate the signal using the
> step and direction channels but never figured out exactly how it works.
>
> It turns out I need a 12.5 Khz signal at 50% duty cycle, not the 25 Khz but cant
> figure out how to calculate it properly. Can anyone help?
>
> The code below is based on an example program that came with the controller.
>
> void StartChargePump()
> {
> int Frequency;
> double DutyCycle, Period;
>
> int Pulse=200; // 1000 Gives approx, 5Khz signal. 200 gives approx 25 khz signal
>
> FPGA(STEP_PULSE_LENGTH_ADD) = Pulse;
>
> DutyCycle= 0.2978; // Note Duty Cycle can't be zero (useful range 0.02 - 0.98)
>
> Period = Pulse/DutyCycle;
>
> Frequency = (int)(0x7FFFFF/Period);
>
> FPGA(STEP_RATE_ADD+0) = Frequency; // put 23 bit frequency
> FPGA(STEP_RATE_ADD+1) = Frequency>>8;
> FPGA(STEP_RATE_ADD+2) = Frequency>>16;
> FPGA(STEP_RATE_ADD+3) = 0x88 + SCHPChanel; // combine enable, Drive High and low
> mode, channel
> }
>
> Thanks
> EK
>
Group: DynoMotion Message: 609 From: Tom Kerekes Date: 8/25/2010
Subject: Re: Need help with a frequency generator.
Hi EK,
 
Basically output a 23 bit number that ranges from 0 to 0x7FFFFF that linearly scales from 0 Hz to 16.67 Mhz
 
so for example compute the period you want in terms of 16.67MHz clocks.
 
Period = 16.67MHz/12.5KHz = 1333.6 clocks
 
then compute and set the frequency
 
Frequency = (int)(0x7FFFFF/Period);
FPGA(STEP_RATE_ADD+0) = Frequency; // put 23 bit frequency
FPGA(STEP_RATE_ADD+1) = Frequency>>8;
FPGA(STEP_RATE_ADD+2) = Frequency>>16;
FPGA(STEP_RATE_ADD+3) = 0x88 + SCHPChanel; // combine enable, Drive High and low mode, channel
TK

Group: DynoMotion Message: 611 From: ekonradsson Date: 8/26/2010
Subject: Re: Need help with a frequency generator.
Thank for the explanation. Much appreciated. Lets just hope the 4us pulse is long enough.

EK

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi EK,
>
> Basically output a 23 bit number that ranges from 0 to 0x7FFFFF that linearly
> scales from 0 Hz to 16.67 Mhz
>
> so for example compute the period you want in terms of 16.67MHz clocks.
>
> Period = 16.67MHz/12.5KHz = 1333.6 clocks
>
> then compute and set the frequency
>
> Frequency = (int)(0x7FFFFF/Period);
>
> FPGA(STEP_RATE_ADD+0) = Frequency; // put 23 bit frequency
> FPGA(STEP_RATE_ADD+1) = Frequency>>8;
> FPGA(STEP_RATE_ADD+2) = Frequency>>16;
> FPGA(STEP_RATE_ADD+3) = 0x88 + SCHPChanel; // combine enable, Drive High and low
> mode, channel
>
> TK
>
>
>
> ________________________________
> From: ekonradsson <erlendur.konradsson@...>
> To: DynoMotion@yahoogroups.com
> Sent: Wed, August 25, 2010 6:34:03 PM
> Subject: [DynoMotion] Re: Need help with a frequency generator.
>
>  
> That might explain my problem. But if a stay with the Step/Dir generator and use
> 4us pulse, how would I set it up for approx 12.5 khz frequency?
>
> Thanks
> EK
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi EK,
> >
> > You can't get a 50% duty cycle pulse at 25KHz with the Step/Dir Generators
> > because that would require a 20us pulse every 40us.  The max pulse size for
> >the
> >
> > Step/Dir Generator is ~4us (setting of 63 at 16.67MHz).
> >
> > Your code example below is setting a value larger than 63 as the pulse length.
> >
> > Consider using a PWM to generate the signal.  You won't be able to generate
> > exactly 25 KHz but I can't imagine that the frequency would be critical for a
> > charge pump.
> >
> > Regards
> > TK
> >
> >
> >
> > ________________________________
> > From: ekonradsson <erlendur.konradsson@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Tue, August 24, 2010 5:04:52 PM
> > Subject: [DynoMotion] Need help with a frequency generator.
> >
> >  
> > I posted a few weeks ago about how to use the PWM generator to generate a 25Khz
> >
> > signal. I managed through trial and error to approximate the signal using the
> > step and direction channels but never figured out exactly how it works.
> >
> > It turns out I need a 12.5 Khz signal at 50% duty cycle, not the 25 Khz but
> >cant
> >
> > figure out how to calculate it properly. Can anyone help?
> >
> > The code below is based on an example program that came with the controller.
> >
> > void StartChargePump()
> > {
> > int Frequency;
> > double DutyCycle, Period;
> >
> > int Pulse=200; // 1000 Gives approx, 5Khz signal. 200 gives approx 25 khz
> >signal
> >
> > FPGA(STEP_PULSE_LENGTH_ADD) = Pulse;
> >
> > DutyCycle= 0.2978; // Note Duty Cycle can't be zero (useful range 0.02 - 0.98)
> >
> > Period = Pulse/DutyCycle;
> >
> > Frequency = (int)(0x7FFFFF/Period);
> >
> > FPGA(STEP_RATE_ADD+0) = Frequency; // put 23 bit frequency
> > FPGA(STEP_RATE_ADD+1) = Frequency>>8;
> > FPGA(STEP_RATE_ADD+2) = Frequency>>16;
> > FPGA(STEP_RATE_ADD+3) = 0x88 + SCHPChanel; // combine enable, Drive High and
> >low
> >
> > mode, channel
> > }
> >
> > Thanks
> > EK
> >
>